
#
# Program ID Number:Program4.s
# Written by    :Beatris Rusu
# Date Created  :9/18/08
# Revision:	1.0
# Revisions made, date of revision, author:
#	First release   	Beatris Rusu
.text

.globl main
.globl For
.globl End
.globl Space
.globl replace_0A
	
# 
#Description: get input string from the console 
#Internal registers used:  
#Declaration  int inString(char *str) 
################
.globl inString 
inString:
        addi    $sp, $sp, -4   	# Make space on stack.
        sw      $ra, 0($sp)    	# Save return address.
           
        # simulator code to get string from console  
        # $a0 must contain pointer to input buffer
        li	$v0, 8  	# code for get string
        syscall                 # get string
        # $a1 contains length of string on return

retinString: 
        lw      $ra, 0($sp)     # Restore return address.
        addi    $sp, $sp, 4     # Restore stack pointer.
        jr      $ra            	# Return.
        
 
 
 # 
 #Description: output a string to the console 
 #Internal registers used:  
 #Declaration  outString(char *str) 
 ################
 .globl outString 
 outString:
         addi    $sp, $sp, -4   	# Make space on stack.
         sw      $ra, 0($sp)    	# Save return address.
            
         # simulator code to display string on console
         # a0 must contain pointer to string 
         li	$v0, 4  	# code for print string
         syscall                 # Print string .
 
 retoutString: 
         lw      $ra, 0($sp)     # Restore return address.
         addi    $sp, $sp, 4     # Restore stack pointer.
         jr      $ra            	# Return.




# 
#Description: read an integer from the console 
#Internal registers used:  
#Declaration  (int num)inInt(void) 
############
.globl inInt 
inInt:
        addi 	$sp, $sp, -4    # Make space on stack.
        sw      $ra, 0($sp)     # Save return address.
           
        # simulator code to get integer from console
        li	$v0, 5  	# code for get integer
        syscall                 # get integer
        # integer is returned in $v0

retinInt: 
        lw      $ra, 0($sp)     # Restore return address.
        addi    $sp, $sp, 4     # Restore stack pointer.
        jr      $ra		# Return.

# 
#Description: output an integer to the console 
#Internal registers used:  
#Declaration  outInt(int) 
#############
.globl outInt 
outInt:
        addi    $sp, $sp, -4      # Make space on stack.
        sw      $ra, 0($sp)       # Save return address.
           
        # simulator code to display integer on console
        # $a0 must contain value to print 
        li	$v0, 1  	# code for print integer
        syscall                     # Print string .
        
retoutInt: 
        lw      $ra, 0($sp)     # Restore return address.
        addi    $sp, $sp, 4     # Restore stack pointer.
        jr      $ra            	# Return.






main:
	addi		$sp, $sp, -4	# Make space on stack.
	sw		$ra, 0($sp)	
	
	la		$a0, Input	#save the address where I want to input the characters from the user
	#la		$a1, Output

	jal 		inString
	
	li		$t1, 0x0a	#t1 will be the next line character
	li		$t5, 0x20	#t5 it contains the number in hexa for a space(blank)	
	li		$t6, 0		#t6 contains null(\0)
	
	move		$s0, $a0
	#move		$s1, $a1
	
	For:
		lb 	$t2, ($s0)		#load the byte located at the address which s0 contains
		beq	$t2, $t1, replace	#test if the byte loaded contains next line character(that means it is the end of the string)
		beq 	$t2, $t5, Continue	#test if the loaded byte is a space, if it is then just continue
		and	$t2,$t2, 0xDF		#if not then convert the character to an upper case character
		sb	$t2, ($s0)		#store it back to the memory location(s0 contains the address to it)
		j 	Continue		# and continue the process:)
		
		replace: 	sb	$t6, ($s0)	#replace the next line character with null	
				j	End		#and end the process!!!
				
		Continue: 	addi	$s0, 1 		#go to the next bite
				#addi	$s1, 1		#go to the next byte
				j For			#repeat the process, in other words, it will go to the next character
	
	End:
		
	jal		outString	#display it on the console
	



	jal	inInt
	move	$t0, $v0
	
	la	$a0, Output2	
	move	$t1,$a0
	sw	$t0, ($t1)
	
	la	$a0, Output2
	jal	outString	



li	$v0, 0		# Return zero.
lw	$ra, 0($sp)	# Restore return address.
addi	$sp, $sp, 4	# Restore stack pointer.

jr	$ra



.data
name:.asciiz "MyName"
endl:.asciiz "\n"
Input: .space 50

Output: .space 50
Input2:.space 50
Output2: .space 50
